# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: db\tables\workers.py
__author__ = "sanyi"
from sqlalchemy import *
from sqlalchemy.orm import mapper
from sqlalchemy.dialects.postgresql import JSONB as TYPE_JSONB
from db.tables import metadata


class LocalWorker:
    SCANNING_APP = "wvs"
    WORKER_ID = "ffffffff-ffff-ffff-ffff-ffffffffffff"
    DESCRIPTION = "Main Installation"


class WorkerTypes:
    AUTO = "auto"
    MANUAL = "manual"
    OBSOLETE = "obsolete"


class WorkerStatus:
    OFFLINE = "offline"
    ONLINE = "online"
    SUSPENDING = "suspended"
    SUSPENDED = "suspended"
    STARTING = "starting"
    DETACHED = "detached"
    STOPPING = "stopping"
    TERMINATED = "terminated"

    @staticmethod
    def is_usable(worker):
        if worker["authorization"] != WorkerAuthorization.AUTHORIZED:
            return False


class WorkerAuthorization:
    PENDING = "pending"
    REJECTED = "rejected"
    AUTHORIZED = "authorized"
    DETACHED = "detached"
    NONE = "none"


WorkersTable = Table(
    "workers",
    metadata,
    Column("worker_id", TEXT, primary_key=True),
    Column("status", TEXT, index=True),
    Column("scanning_app", TEXT, index=True, nullable=False),
    Column("endpoint", TEXT),
    Column("max_job_count", INTEGER, default=4),
    Column("created", DateTime(true), default="now()"),
    Column("start_date", DateTime(true)),
    Column("shutdown_date", DateTime(true)),
    Column("api_key", TEXT),
    Column("ssl_verify", BOOLEAN, default=False),
    Column("worker_type", TEXT, default="fixed"),
    Column("description", TEXT),
    Column("authorization", TEXT),
    Column("info", TYPE_JSONB),
)


class WorkerRow(object):
    worker_id = None
    status = None
    scanning_app = None
    worker_type = None
    endpoint = None
    description = None
    max_job_count = None
    authorization = None

    def __str__(self):
        return "R_worker[%s:%s]" % (self.worker_id, self.scanning_app)

    def __repr__(self):
        return self.__str__()


mapper(WorkerRow, WorkersTable)
